package com.dragon.shop_user.controller;

import com.dragon.shop_common.utils.AjaxResult;
import com.dragon.shop_user.config.NaCosConfig;
import com.dragon.shop_user.domain.vo.NaCos2Vo;
import com.dragon.shop_user.domain.vo.NacosVo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

// 动态刷新配置
@RefreshScope
@RestController
@RequestMapping("/hellWord")
public class HelloWordController {

    @Value(value = "${mdx-shop-user.test2}")
    private String userId;

    @Value(value = "${test3}")
    private String test3;

    @Resource
    private NaCosConfig naCosConfig;


    @GetMapping("/getUserConfigTest")
    public String getUserConfigTest() {
        return (userId != null ? "userId:" + userId : "userId 未获取到配置 - ") + (test3 != null ? "   test3:" + test3 : "test3 未获取到配置");
    }

    @GetMapping("/getUserConfigTest2")
    public AjaxResult<NacosVo> getUserConfigTest2() {
        return AjaxResult.succeedWith(NacosVo
                .builder()
                        .userId(userId != null ? userId : "未获取到配置")
                        .test3(test3 != null ? test3 : "未获取到配置")
                .build()
        );
    }

    @GetMapping("/getUserConfigTest3")
    public AjaxResult<NaCos2Vo> getUserConfigTest3() {
        return AjaxResult.succeedWith(NaCos2Vo
                .builder()
                .username(naCosConfig.getUsername())
                .password(naCosConfig.getPassword())
                .build()
        );
    }

}
